package cn.ito.zjgsu.domain.wrapper;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.ito.zjgsu.domain.Authority;

public class AuthorityWrapper {
	
	
	private Authority authority;

	public AuthorityWrapper(){}
	public AuthorityWrapper(Authority authority){
		this.authority = authority;
	}
	
	public Authority getAuthority() {
		return authority;
	}

	public void setAuthority(Authority authority) {
		this.authority = authority;
	}
	
	
	public String toJsonObjectString(){	
		return toJsonObject().toJSONString();
	}
	
	public JSONObject toJsonObject(){
		JSONObject json = new JSONObject();	
		initDepartmentField(json);		
		return json;
	}

	private void initDepartmentField(JSONObject json) {
		json.put("id", authority.getAuthorityId());
		json.put("CreateTime", authority.getAuthorityCreateTime());
		json.put("Description", authority.getAuthorityDescription());
		json.put("Name", authority.getAuthorityName());
	}
	
	public static JSONArray toJsonArray(List<AuthorityWrapper> authorityWrapper){
		JSONArray array = new JSONArray();
		for(AuthorityWrapper aw : authorityWrapper){
			array.add(aw.toJsonObject());
		}
		return array;
	}
	
	public static String toJsonArrayString(JSONArray array){
		return array.toJSONString();
	}
	public static String toJsonArrayString(List<AuthorityWrapper> authorityWrapper){
		return toJsonArray(authorityWrapper).toJSONString();
	}
	
	
	public static List<AuthorityWrapper> WrapAuthority(List<Authority> authorities){
		if(authorities !=null){
			List<AuthorityWrapper> authorityWrappers = new ArrayList<AuthorityWrapper>();
			for (Authority a : authorities) {
				authorityWrappers.add(new AuthorityWrapper(a));
			}
			return authorityWrappers;
		}
		return null;
	}
}
